//
//  DOMHTMLHtmlElementExtensions.m
//  WebClipper
//
//  Created by Daniel Braun on 22/02/07.
//  Copyright 2007Daniel Braun http://page-appart.net, http://braun.daniel.free.fr  All rights reserved.
//

#import "DOMHTMLHtmlElementExtensions.h"
#import "objcExt.h"

@implementation  DOMNode  (DOMArrayExtensions)

- (NSArray *) arrayChildNodes
{
	//id z= [self valueForKey:@"childNodes"];
	//DOMNodeList *nl=[self childNodes];
	//int c=[nl length];
	NSMutableArray *a=[NSMutableArray arrayWithCapacity:10];	
	DOMNode *el;
	for (el=[self firstChild]; el; el=[el nextSibling]) {
		//NSLog(@"print el %@ (%@) at %p\n", el,[el nodeName], el);
		[a addObject:el];
		if ([self lastChild]==el) break;
	}
	return a;
}
- (int) mcount
{
	DOMNodeList *nl=[self childNodes];
	int c=[nl length];
	return c;
}


- (id) valueForKey:(NSString *) key
{
	id v=nil;
	int x=1;
	if (x) v=[super valueForKey:key];
	//NSLog(@"value for %@ : %@\n", key, v);
	if (!v || [v isKindOfClass:[WebUndefined class]]) {
		SEL sel=selFromString(key);
		if ((sel) && [self respondsToSelector:sel]) {
			v=[self performSelector:sel];
		}
	}
	if ( [v isKindOfClass:[WebUndefined class]]) v=@"";
	return v;
}

#if 0
- (id) nodeValue
{
	return @"coucou";
}
- (id) nodeName
{
	return @"polp";
}
#endif
@end